Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare com.microsoft.azure:adal4j dependency as optional #22584

Closed

Conversation

knutwannheden
Copy link
Contributor

The quarkus-jdbc-mssql extension has a dependency on com.microsoft.azure:adal4j, which apparently is required for compilation to succeed.

To allow Quarkus applications to work with newer versions of com.microsoft.sqlserver:mssql-jdbc (currently not possible in Quarkus, because newer versions have issues with native mode), this dependency is declared as optional, since the newer versions have replaced this dependency with com.azure:azure-identity to support Active AD based authentication.

Also note that this dependency is also declared as optional by the mssql-jdbc module and that a Quarkus application unfortunately cannot work with Maven exclusions to exclude the dependency when imported via the Quarkus BOM.

@quarkus-bot
Copy link

quarkus-bot bot commented Jan 3, 2022

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 2bdf318

Status Name Step Failures Logs Raw logs
Native Tests - Data1 Build Failures Logs Raw logs

Failures

⚙️ Native Tests - Data1 #

- Failing: integration-tests/jpa-mssql 

📦 integration-tests/jpa-mssql

Failed to execute goal io.quarkus:quarkus-maven-plugin:999-SNAPSHOT:build (default) on project quarkus-integration-test-jpa-mssql: Failed to build quarkus application

@knutwannheden
Copy link
Contributor Author

@Sanne The native image generation fails with the following error, since I marked a dependency as optional. I don't really know much about native image generation using GraalVM.

Error: Cannot find com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken, com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils can not be loaded, due to com/microsoft/aad/adal4j/AuthenticationException not being available in the classpath. Are you missing a dependency in your classpath?

To me it seems like it would make sense to only native-compile this method if also the optional adal4j dependency is actually on the classpath. Is there some way to achieve this?

@geoand
Copy link
Contributor

geoand commented Jan 3, 2022

To me it seems like it would make sense to only native-compile this method if also the optional adal4j dependency is actually on the classpath. Is there some way to achieve this?

You would likely need to make io.quarkus.jdbc.mssql.runtime.graal.com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils a conditional substitution (similar to what is done here)

@knutwannheden
Copy link
Contributor Author

Thanks for the tip! I will look into it.

@knutwannheden
Copy link
Contributor Author

Hmm... The substitute actually already exists:

@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils")
@Substitute
final class SQLServerADAL4JUtils {
@Alias
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)
static final private java.util.logging.Logger adal4jLogger = null;
@Substitute
static QuarkusSqlFedAuthToken getSqlFedAuthToken(QuarkusSqlFedAuthInfo fedAuthInfo, String user, String password,
String authenticationString) {
throw new IllegalStateException("Quarkus does not support Active Directory based authentication");
}

Apparently an attempt is still made to load the substituted class. All fields and methods in that class have been substituted. The mentioned class AuthenticationException which isn't available should not be required anymore. It looks like this is some kind of limitation of the GraalVM tooling then. Maybe I could try to substitute that as well?

@geoand
Copy link
Contributor

geoand commented Jan 3, 2022

Hmm... The substitute actually already exists:

Yes my point was that it might need to be conditionally substituted.

@knutwannheden knutwannheden force-pushed the make-adal4j-optional branch 2 times, most recently from 9488690 to 6a13582 Compare January 3, 2022 15:43
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 3, 2022

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 6a13582

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Build Failures Logs Raw logs

Failures

⚙️ Initial JDK 11 Build #

- Failing: extensions/jdbc/jdbc-mssql/runtime 
! Skipped: devtools/bom-descriptor-json docs extensions/jdbc/jdbc-mssql/deployment and 2 more

📦 extensions/jdbc/jdbc-mssql/runtime

Failed to execute goal net.revelc.code:impsort-maven-plugin:1.6.2:check (check-imports) on project quarkus-jdbc-mssql: Imports are not sorted in /home/runner/work/quarkus/quarkus/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/graal/com/microsoft/sqlserver/jdbc/SQLServerJDBCSubstitutions.java

The  `quarkus-jdbc-mssql` extension has a dependency on `com.microsoft.azure:adal4j`, which apparently is required for compilation to succeed.

To allow Quarkus applications to work with newer versions of `com.microsoft.sqlserver:mssql-jdbc` (currently not possible in Quarkus, because newer versions have issues with native mode), this dependency is declared as optional, since the newer versions have replaced this dependency with `com.azure:azure-identity` to support Active AD based authentication.

Also note that this dependency is also declared as optional by the `mssql-jdbc` module and that a Quarkus application unfortunately cannot work with Maven exclusions to exclude the dependency when imported via the Quarkus BOM.
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 3, 2022

Failing Jobs - Building 6ee3e24

Status Name Step Failures Logs Raw logs
Native Tests - Data1 Build Failures Logs Raw logs

Failures

⚙️ Native Tests - Data1 #

- Failing: integration-tests/jpa-mssql 

📦 integration-tests/jpa-mssql

Failed to execute goal io.quarkus:quarkus-maven-plugin:999-SNAPSHOT:build (default) on project quarkus-integration-test-jpa-mssql: Failed to build quarkus application

@Sanne
Copy link
Member

Sanne commented Jan 4, 2022

Maybe we should try upgrading the driver?

I remember giving it a shot and then aborting as it was more complex than expected and couldn't dedicate some proper cycles to it, but we should look at that again.

@knutwannheden
Copy link
Contributor Author

I cannot find a way to mark the adal4j dependency as optional and I probably tried some of the same things you did. I also stumbled across the oracle/graal#819 issue you created at some point. I am a bit surprised by this limitation.

Trying to upgrade the driver would indeed be nice. That is also why I wanted to get rid of this dependency. I will give it another try and see how far I get.

@Sanne
Copy link
Member

Sanne commented Jan 6, 2022

many thanks for giving it another shot @knutwannheden , appreciate it :)

I've also pinged @galderz in hope we can restart a conversation with the graalvm about such issues.

@knutwannheden
Copy link
Contributor Author

Basically I run into the same issues with the new driver. I could try to declare some of the driver's optional dependencies as non-optional (like you did for adal4j) and see if I get it to work that way.

I suppose it would be possible to set compiler flags like --report-unsupported-elements-at-runtime when the MSSQL JDBC extension is present, but that seems like a very slippery slope.

@Sanne
Copy link
Member

Sanne commented Jan 6, 2022

I suppose it would be possible to set compiler flags like --report-unsupported-elements-at-runtime when the MSSQL JDBC extension is present, but that seems like a very slippery slope.

Right that's too slippery: it's a global flag and introduces various other issues, which might even break other extensions as we've observed it having side-effects on other compiler flags.

And I don't want the presence/absence of one extension to affect any other extension: the amount of permutations would make it all untestable.

See also:

+1 to keep the dependencies around: dead code elimitation is going to get rid of the code anyway so it's not like it would produce a suboptimal native binary; at worst it will eat a little disk space in JVM mode.

@gsmet
Copy link
Member

gsmet commented Jan 12, 2022

@knutwannheden so what should we do with this PR? Should we close it or do you plan to upgrade the driver here?

Thanks!

@gastaldi
Copy link
Contributor

@knutwannheden friendly ping on #22584 (comment) here :)

@knutwannheden
Copy link
Contributor Author

I tried everything I could think of but I failed. I lack the experience with GraalVM, but it seems like the tooling to do these kinds of things is also lacking a bit.

@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label Feb 23, 2022
gastaldi added a commit to gastaldi/quarkus that referenced this pull request Feb 24, 2022
gastaldi added a commit to gastaldi/quarkus that referenced this pull request Feb 24, 2022
@galderz
Copy link
Member

galderz commented Mar 3, 2022

@knutwannheden Indeed the tooling for getting around this issues is not great. This is why I created oracle/graal#3929. A couple of months ago I explored the feasibility of implementing it but couldn't find an easy way and had to move to other priorities. In the past few days a PR has been submitted that might find a way around your issues, but we're not fully satisfied with the way it works (see here).

sschu pushed a commit to sschu/quarkus that referenced this pull request Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants